home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / ASSEMBLE / H145.ZIP / ASXXXX_3.ZIP / M11ADR.C < prev    next >
C/C++ Source or Header  |  1990-07-18  |  3KB  |  190 lines

  1. /* m11adr.c */
  2.  
  3. /*
  4.  * (C) Copyright 1989,1990
  5.  * All Rights Reserved
  6.  *
  7.  * Alan R. Baldwin
  8.  * 721 Berkeley St.
  9.  * Kent, Ohio  44240
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <setjmp.h>
  14. #include "asm.h"
  15. #include "m6811.h"
  16.  
  17. int
  18. addr(esp)
  19. register struct expr *esp;
  20. {
  21.     register c;
  22.     register struct area *espa;
  23.     register char *tcp;
  24.  
  25.     if ((c = getnb()) == '#') {
  26.         expr(esp, 0);
  27.         esp->e_mode = S_IMMED;
  28.     } else
  29.     if (c == ',') {
  30.         esp->e_mode = 0;
  31.         esp->e_flag = 0;
  32.         esp->e_addr = 0;
  33.         esp->e_base.e_ap = NULL;
  34.         c = admode(abdxy);
  35.         if (c == S_X) {
  36.             esp->e_mode = S_INDX;
  37.         } else
  38.         if (c == S_Y) {
  39.             esp->e_mode = S_INDY;
  40.         } else {
  41.             aerr();
  42.         }
  43.     } else
  44.     if (c == '*') {
  45.         expr(esp, 0);
  46.         esp->e_mode = S_DIR;
  47.         if (more()) {
  48.             comma();
  49.             tcp = ip;
  50.             if ((c = admode(abdxy)) != 0) {
  51.                 if (c == S_X) {
  52.                     esp->e_mode = S_INDX;
  53.                 } else
  54.                 if (c == S_Y) {
  55.                     esp->e_mode = S_INDY;
  56.                 } else {
  57.                     aerr();
  58.                 }
  59.             } else {
  60.                 ip = --tcp;
  61.             }
  62.         }
  63.     } else {
  64.         unget(c);
  65.         if ((esp->e_mode = admode(abdxy)) != 0) {
  66.             ;
  67.         } else {
  68.             expr(esp, 0);
  69.             if (more()) {
  70.                 comma();
  71.                 tcp = ip;
  72.                 if ((c = admode(abdxy)) != 0) {
  73.                     if (c == S_X) {
  74.                         esp->e_mode = S_INDX;
  75.                     } else
  76.                     if (c == S_Y) {
  77.                         esp->e_mode = S_INDY;
  78.                     } else {
  79.                         aerr();
  80.                     }
  81.                 } else {
  82.                     ip = --tcp;
  83.                 }
  84.             } else {
  85.                 if (esp->e_flag == 0 &&
  86.                     esp->e_base.e_ap == NULL &&
  87.                     (esp->e_addr & ~0xFF) == 0 ) {
  88.                     esp->e_mode = S_DIR;
  89.                 } else {
  90.                     esp->e_mode = S_EXT;
  91.                 }
  92.             }
  93.         }
  94.     }
  95.     c = esp->e_mode;
  96.     if (c == S_INDX || c == S_INDY || c == S_DIR) {
  97.         if (esp->e_flag == 0 && esp->e_base.e_ap == NULL) {
  98.             if (esp->e_addr & ~0xFF)
  99.                 err('d');
  100.         }
  101.     }
  102.     return (esp->e_mode);
  103. }
  104.     
  105. /*
  106.  * Enter admode() to search a specific addressing mode table
  107.  * for a match. Return the addressing value on a match or
  108.  * zero for no match.
  109.  */
  110. int
  111. admode(sp)
  112. register struct adsym *sp;
  113. {
  114.     register char *ptr;
  115.     register int i;
  116.     unget(getnb());
  117.     i = 0;
  118.     while ( *(ptr = (char *) &sp[i]) ) {
  119.         if (srch(ptr)) {
  120.             return(sp[i].a_val);
  121.         }
  122.         i++;
  123.     }
  124.     return(0);
  125. }
  126.  
  127. /*
  128.  *      srch --- does string match ?
  129.  */
  130. int
  131. srch(str)
  132. register char *str;
  133. {
  134.     register char *ptr;
  135.     ptr = ip;
  136.  
  137. #if    CASE_SENSITIVE
  138.     while (*ptr && *str) {
  139.         if(*ptr != *str)
  140.             break;
  141.         ptr++;
  142.         str++;
  143.     }
  144.     if (*ptr == *str) {
  145.         ip = ptr;
  146.         return(1);
  147.     }
  148. #else
  149.     while (*ptr && *str) {
  150.         if(ccase[*ptr] != ccase[*str])
  151.             break;
  152.         ptr++;
  153.         str++;
  154.     }
  155.     if (ccase[*ptr] == ccase[*str]) {
  156.         ip = ptr;
  157.         return(1);
  158.     }
  159. #endif
  160.  
  161.     if (!*str)
  162.         if (any(*ptr," \t\n,];")) {
  163.             ip = ptr;
  164.             return(1);
  165.         }
  166.     return(0);
  167. }
  168.  
  169. /*
  170.  *      any --- does str contain c?
  171.  */
  172. int
  173. any(c,str)
  174. char    c, *str;
  175. {
  176.     while (*str)
  177.         if(*str++ == c)
  178.             return(1);
  179.     return(0);
  180. }
  181.  
  182. struct adsym    abdxy[] = {    /* a, b, d, x, or y registers */
  183.     "a",    S_A,
  184.     "b",    S_B,
  185.     "d",    S_D,
  186.     "x",    S_X,
  187.     "y",    S_Y,
  188.     "",    0x00
  189. };
  190.